<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html lang="en">
<head>
    <title>新增员工</title>
    <jsp:include page="easyuiIncludeJS.jsp"/>
    <script type="text/javascript">
        function exit() {
            window.location.href = "${pageContext.request.contextPath}/admin/emp/list";
        }
        $(function () {
            $('#empName').textbox({
                prompt: '员工姓名',
                required: true,
                validType:'length[1,20]',
                missingMessage: "请输入员工姓名"
            });
        })

        function saveEmp() {
            var empName=$("#empName").val();
            var phone=$("#phone").val();
            var qqCode=$("#qqCode").val();
            var weixin=$("#weixin").val();
            var email=$("#email").val();
            var university=$("#university").val();
            var address=$("#address").val();
            var remark=$("#remark").val();
            
            var major=$("#major").val();
            var isok = true;
            if(empName==""){
                alert('请输入员工姓名');
                $("#empName").focus();
                return;
            }
            if(phone==""){
                alert('请输入手机号码');
                $("#phone").focus();
                return;
            }
            
            if(qqCode!=""){
                var isqqCode=/[1-9][0-9]{4,}/;
                if(!isqqCode.test(qqCode)){
                    alert('QQ号码格式错误');
                    $("#qqCode").focus();
                    return;
                }
            }
            if(weixin!=""){
                  return;
                if(weixin.length>20){
                    alert("微信号码过长");
                    return;
                }
            }
            
            if(university.length>30){
                alert('毕业学校长度过长');
                $("#university").focus();
                return;
            }
            if(major.length>30){
                alert('专业长度过长');
                $("#major").focus();
                return;
            }
            if(address.length>100){
                alert('家庭地址长度过长');
                $("#address").focus();
                return;
            }

            $.ajax({
                url:'${pageContext.request.contextPath}/admin/emp/getPhone',
                type:'post',
                dataType: 'json',
                data:{
                    "phone":$("#phone").val(),
                    "empId":$("input[name='empId']").val()
                },
                async : false,//同步  
                success: function (data) {
                    if (data.ph == 1) {
                        alert('手机号已存在');
                        $("#phone").focus();
                        isok=false;
                        return false;
                    }
                }
            });
            if(isok){
                document.forms[0].submit();
            }
        }


    </script>
</head>
<body>
<center>
<form name="form1" id="form1"  action="${pageContext.request.contextPath}/admin/emp/save">
    <table style="height: 370px;width: 700px;margin-top: 10px" border="0">
        <input type="hidden" id="empId" name="empId" value="${emp.empId}"/>
        <tr style="height: 40px">
            <td align="right">员工姓名:</td>
            <td align="left"><input id="empName" name="empName" placeholder="请输入员工姓名" value="${emp.empName}" style="width:200px;"></td>
            <td align="right">部门名称:</td>
            <td align="left">
                <select  id="depId" name="depId"  style="width:205px;" >
                    <c:forEach items="${listDep}" var="d">
                        <c:if test="${d.depid==emp.depId}">
                            <option value="${d.depid}" selected="selected">${d.depName}</option>
                        </c:if>
                        <c:if test="${d.depid!=emp.depId}">
                            <option value="${d.depid}">${d.depName}</option>
                        </c:if>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr  style="height: 40px">
            <td align="right">手机号码:</td>
            <td align="left">
                <input type="text" id="phone" name="phone" value="${emp.phone}" placeholder="请输入手机号"  style="width:200px;">
            </td>
            <td align="right">性别:</td>
            <td align="left">
                <select  id="sex" name="sex"    style="width:205px;">
                    <option value="男" <c:if test="${emp.sex=='男'}">selected="selected"</c:if>>男</option>
                    <option value="女" <c:if test="${emp.sex=='女'}">selected="selected"</c:if>>女</option>
                </select>
            </td>
        </tr>

        

        <tr style="height: 40px">
            <td align="right">QQ号码:</td>
            <td align="left">
                <input type="text" id="qqCode"  name="qqCode" value="${emp.qqCode}"placeholder="请输入QQ号码" style="width:200px;">
            </td>
            <td align="right">家庭地址:</td>
            <td align="left">
                <input type="text"  name="address" id="address" value="${emp.address}" placeholder="请输入家庭地址"  style="width:200px;">
            </td>
        </tr>

        <tr style="height: 40px">
            <td align="right">微信号码:</td>
            <td align="left">
                <input type="text" id="weixin" name="weixin" value="${emp.weixin}" placeholder="请输入微信号码"  style="width:200px;">
            </td>
            <td align="right">邮箱地址:</td>
            <td align="left">
                <input type="text" id="email"  name="email" value="${emp.email}"placeholder="请输入邮箱地址" style="width:200px;">
            </td>
        </tr>

        <tr style="height: 40px">
            <td align="right">毕业学校:</td>
            <td align="left">
                <input type="text" id="university"  name="university" value="${emp.university}"placeholder="请输入毕业学校" style="width:200px;">
            </td>
            <td align="right">专业:</td>
            <td align="left">
                <input type="text" id="major"  name="major" value="${emp.major}"placeholder="请输入专业" style="width:200px;">
            </td>
        </tr>

        <tr style="height: 40px">
            <td align="right">学历:</td>
            <td align="left">
                <select  id="education" name="education"   style="width:205px;">
                    <option value="高中以下" <c:if test="${emp.education=='高中以下'}">selected="selected"</c:if>>高中以下</option>
                    <option value="专科" <c:if test="${emp.education=='专科'}">selected="selected"</c:if>>专科</option>
                    <option value="本科" <c:if test="${emp.education=='本科'}">selected="selected"</c:if>>本科</option>
                    <option value="本科以上" <c:if test="${emp.education=='本科以上'}">selected="selected"</c:if>>本科以上</option>
                </select>
            </td>
            <td align="right">登录密码:</td>
            <td align="left">
                <input type="text" disabled placeholder="默认密码为123456" style="width:200px;">
            </td>
        </tr>
        <tr style="height: 40px">
            <td align="right" colspan="2">
                <a class="easyui-linkbutton" icon="icon-save"  plain="true" href="javascript:void(0);"
                   onclick="saveEmp();">保 存</a>
                   <a class="easyui-linkbutton" icon="icon-undo"  plain="true" href="javascript:void(0);"
   onclick="exit();">返 回</a>
        </tr>
    </table>
</form>
</center>

</body>
</html>
